#python -u "d:\yurianime\YuriAnimeResourcesClassify.py"

f1 = open("D:\\yurianime\\YuriAnimeResources2.txt","r",encoding="utf-8")
lines = f1.readlines()
f1.close()
f2 = open("D:\\yurianime\\YuriAnimeResourcesClassify.csv","w",encoding="utf-8")
index = 0
while index < len(lines):
    if lines[index-1] == "\n":
        anime = lines[index].strip("\n")
        #print("\n")
        f2.write(",,,,,\n")
        #print(",,,,,")
        f2.write("番名,資源名,簡繁,分辨率,鏈接,\n")
        #print("番名,資源名,簡繁,分辨率,鏈接,")
    elif "miobt" in lines[index]:
        resource = lines[index-1].strip("\n")
        f2.write(anime+","+resource+",")
        #print(anime+","+resource,end = ",")
        if "GB" in resource or "简" in resource:
            f2.write("簡體,")
            #print("簡體",end = ",")
        elif "BIG5" in resource or "繁" in resource:
            f2.write("繁體,")
            #print("繁體",end = ",")
        else:
            f2.write("Null,")
            #print("Null",end = ",")
        if "1080" in resource:
            f2.write("1080,")
            #print("1080",end = ",")
        elif "720" in resource:
            f2.write("720,")
            #print("720",end = ",")
        elif "480" in resource:
            f2.write("480,")
            #print("480",end = ",")
        else:
            f2.write("Null,")
            #print("Null",end = ",")
        f2.write(lines[index].strip("\n")+",\n")
        #print(lines[index].strip("\n")+",")
    index += 1
f2.close()